import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.config.rules.DateType;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
import com.baomidou.mybatisplus.generator.fill.Column;
import org.junit.Test;

import java.util.Collections;

public class test {

    String modelName = "order";

    String path = "D:\\桌面\\毕设\\代码\\后端\\education\\service\\service-" + modelName + "\\src\\main\\java";
    String xmlPath = "D:\\桌面\\毕设\\代码\\后端\\education\\service\\service-" + modelName + "\\src\\main\\java\\com\\ms\\education\\" + modelName + "\\mapper\\xml";

    @Test
    public void generate() {
        FastAutoGenerator.create("jdbc:mysql://192.168.232.130/education?serverTimezone=GMT%2B8&character_set_server =utf8mb4",
                        "root",
                        "123456")
                .globalConfig(builder -> {
                    builder.author("ms") // 设置作者
                            .enableSwagger() // 开启 swagger 模式
                            .outputDir(path) // 指定输出目录
                            .dateType(DateType.ONLY_DATE);//日期类型
                })
                .packageConfig(builder -> {
                    builder.parent("com.ms.education") // 设置父包名
                            .moduleName(modelName) // 设置父包模块名
                            .pathInfo(Collections.singletonMap(OutputFile.xml, xmlPath)); // 设置mapperXml生成路径
                })
                .strategyConfig(builder -> {
                    builder.addInclude("t_order", "t_pay_log") // 设置需要生成的表名
                            .addTablePrefix("edu_", "t_") // 设置过滤表前缀
                            /******************实体类配置***************/
                            .entityBuilder()
                            .enableLombok()//开启lombok
                            .enableTableFieldAnnotation()//表字段注释
                            .logicDeletePropertyName("isDeleted")//逻辑删除
                            .addTableFills(new Column("gmt_create", FieldFill.INSERT))
                            .addTableFills(new Column("gmt_modified", FieldFill.INSERT_UPDATE))
                            /******************控制层***************/
                            .controllerBuilder()
                            .enableHyphenStyle()//开启驼峰连字符
                            .enableRestStyle()//rest风格
                            /******************实业务逻辑层***************/
                            .serviceBuilder()
                            .formatServiceFileName("%sService")
                            .formatServiceImplFileName("%sServiceImp");
                })
                .templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板，默认的是Velocity引擎模板
                .execute();
    }

}
